﻿using System;
using System.Windows.Forms;

namespace AisinGioro.Core.WinForm
{
    public class WinFormHelper
    {
        /// <summary>
        /// 跨线程设置控件状态
        /// </summary>
        public static void SetControlCrossThread(Control ctrl, Action setting)
        {
            if (ctrl.InvokeRequired)
            {
                ctrl.Invoke(setting);
            }
            else
            {
                setting();
            }
        }
        /// <summary>
        /// 跨线程设置控件状态
        /// </summary>
        public static void SetControlCrossThread<T1>(Control ctrl, Action<T1> setting, T1 arg)
        {
            if (ctrl.InvokeRequired)
            {
                ctrl.Invoke(setting, arg);
            }
            else
            {
                setting(arg);
            }
        }
        /// <summary>
        /// 跨线程设置控件状态
        /// </summary>
        public static void SetControlCrossThread<T1, T2>(Control ctrl, Action<T1, T2> setting, T1 arg1, T2 arg2)
        {
            if (ctrl.InvokeRequired)
            {
                ctrl.Invoke(setting, arg1, arg2);
            }
            else
            {
                setting(arg1, arg2);
            }
        }
    }
}
